﻿using BLL;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace 后整理管理系统.数据分析
{
    public partial class 进仓月报表 : Form
    {
        public 进仓月报表()
        {
            InitializeComponent();
        }

        private void 进仓月报表_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                uiComboBox1.Items.Add(DateTime.Now.Year - i);
            }
            uiComboBox1.Text = DateTime.Now.Year.ToString();
            query();
        }
        private void query()
        {
            this.Invoke(new MethodInvoker(() =>
            {
                this.ShowWaitForm("正在生成报表，请等待.............");
                gridControl1.DataSource = 当年进仓报表.CreateReport(DateTime.Parse(uiComboBox1.Text + "-01-01"));
                gridControl2.DataSource = 当年进仓报表.CreateCustomerReport(DateTime.Parse(uiComboBox1.Text + "-01-01"));
                var dt = gridControl1.DataSource as DataTable;
                chart1.Series.Clear();
                var series = new Series("进仓数");
                series.ChartType = SeriesChartType.Line;
                // 设置悬停提示格式
                series.ToolTip = "日期: #VALX\n数量: #VALY";  // 使用内置变量占位符
                                                          //series.IsValueShownAsLabel = false;  // 关闭默认标签显示
                                                          // 绑定数据
                foreach (DataRow row in dt.Rows)
                {
                    series.Points.AddXY(
                        row["月份"].ToString(),
                        row["米数"]);
                }
                chart1.Series.Add(series);
                this.HideWaitForm();
            }));
        }

        private void gridView1_Click(object sender, EventArgs e)
        {
            this.Invoke(new MethodInvoker(() =>
            {
                gridControl3.DataSource = 当年进仓报表.CreateCustomerDetailReport(DateTime.Parse(uiComboBox1.Text + "-" + gridView1.GetFocusedRowCellValue("月份").ToString() + "-01"));
            }));
        }

        private void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            query();
        }
    }
}
